package com.android.sgzcommon.activity;

import android.content.Intent;
import android.os.Bundle;

import com.android.sgzcommon.take_photo.GetPhotoImpl;
import com.android.sgzcommon.take_photo.listener.OnPhotoListener;

import java.io.File;

import androidx.annotation.NonNull;

/**
 * 拍摄或选取一张照片
 * @author sgz
 * @date 2020/6/24
 */
public class BaseGetPhotoActivity extends BaseActivity {

    private GetPhotoImpl mGetPhoto;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mGetPhoto = new GetPhotoImpl(this);
    }

    /**
     * @return
     */
    protected File getTakePhotoDir() {
        if (mGetPhoto != null) {
            return null;
        }
        return null;
    }

    /**
     * 调用系统照相机拍照
     */
    protected void takePhoto(OnPhotoListener listener) {
        if (mGetPhoto != null) {
            mGetPhoto.setPhotoListener(listener);
            mGetPhoto.takePhoto();
        }
    }

    /**
     * 调用选取照片
     */
    protected void choosePhoto(OnPhotoListener listener) {
        if (mGetPhoto != null) {
            mGetPhoto.setPhotoListener(listener);
            mGetPhoto.choosePhoto();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (mGetPhoto != null) {
            mGetPhoto.onActivityResult(requestCode, resultCode, data);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (mGetPhoto != null) {
            mGetPhoto.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}
